<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2024/2/20
 * Time: 9:52
 */

namespace app\api\model;

class UUser extends Base
{
    /**
     * 插入单条数据，并返回ID
     * @param $data
     * @return int|string
     */
    static function insertDataGetID($data = []){
        return self::insertGetId($data);
    }

    /**
     * 单条数据
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findData($where = [], $field = '*'){
        return self::where($where)->field($field)->find();
    }

    /**
     * 读取器，获取完整图片绝对路径
     * @param $url  图片地址
     * @param $data 表中所有数据组成的数组，框架根据当前模型自动获取
     * @return string
     */
    public function getUserImageAttr($url, $data)
    {
        if($data['user_image']){
            return $this->prefixImgUrl($url);
        }else{
            return '';
        }

    }
}